﻿using ZCUtil.Singleton;
using ZCUIManager;
using System.Collections.Generic;
using UnityEngine;
using ZCUtil.DoubleBuffer;

namespace ZCTouchDrawBoard
{
    public class TouchDrawingController : Singleton<TouchDrawingController>
    {
        #region Model And View
        private TouchDrawingView m_TouchDrawingView;
        private TouchDrawingModel m_TouchDrawingModel;
        #endregion

        #region DB
        public DoublePaper DoublePaper { get; set; }
        #endregion

        #region LiveTime
        public void Initialize()
        {
            m_TouchDrawingView = UIManager.Instance.GetUIView<TouchDrawingView>(eUIType.TouchDrawingView);

            m_TouchDrawingModel = new TouchDrawingModel();
            m_TouchDrawingModel.Initialize();
        }

        public void Uninitialize()
        {
            m_TouchDrawingView.Uninitialize();
            m_TouchDrawingModel.Uninitialize();
        }
        #endregion

        #region PublicMethod
        public void UpdatePaintListAction()
        {
            List<PaintAttribute> attributes = m_TouchDrawingModel.UpdatePaintList();
            m_TouchDrawingView.RefreshPaintList(attributes);
        }

        public void UpdateSelectGo(GameObject selectGo)
        {
            m_TouchDrawingView.PaperPanel.SwitchPaper(selectGo);
        }
        #endregion

        #region PublicMethod
        public void SetCreatePaperCallback(CreatePaperCallback callback)
        {
            if (m_TouchDrawingView.PaperPanel == null)
            {
                Logger.e("touch drawing view the paper panel is null.");
                return;
            }
            m_TouchDrawingView.PaperPanel.CreatePaperCallback = callback;
        }

        public void SetClickPaperCallback(ClickPaperCallback callback)
        {
            if (m_TouchDrawingView.PaperPanel == null)
            {
                Logger.e("touch drawing view the paper panel is null.");
                return;
            }
            m_TouchDrawingView.PaperPanel.ClickPaperCallback = callback;
        }

        public void SetClickDownPaperCallback(ClickDownPaperCallback callback)
        {
            if (m_TouchDrawingView.PaperPanel == null)
            {
                Logger.e("touch drawing view the paper panel is null.");
                return;
            }
            m_TouchDrawingView.PaperPanel.ClickDownPaperCallback = callback;
        }

        public void SetClickUpPaperCallback(ClickUpPaperCallback callback)
        {
            if (m_TouchDrawingView.PaperPanel == null)
            {
                Logger.e("touch drawing view the paper panel is null.");
                return;
            }
            m_TouchDrawingView.PaperPanel.ClickUpPaperCallback = callback;
        }

        public void SetDragPaperCallback(DragPaperCallback callback)
        {
            if (m_TouchDrawingView.PaperPanel == null)
            {
                Logger.e("touch drawing view the paper panel is null.");
                return;
            }
            m_TouchDrawingView.PaperPanel.DragPaperCallback = callback;
        }

        public void SetEditPaperCallback(EditPaperCallback callback)
        {
            if (m_TouchDrawingView.PaperPanel == null)
            {
                Logger.e("touch drawing view the paper panel is null.");
                return;
            }
            m_TouchDrawingView.PaperPanel.EditPaperCallback = callback;
        }

        public void SetPaintSizeChangeCallback(PaintSizeChangeCallback callback)
        {
            if (m_TouchDrawingView.PaintPanel == null)
            {
                Logger.e("touch drawing view the paint panel is null.");
                return;
            }
            m_TouchDrawingView.PaintPanel.PaintSizeChangeCallback = callback;
        }

        public void SetActiveViewAction(bool enable)
        {
            if (enable)
            {
                m_TouchDrawingView.Show();
                UpdatePaintListAction();
            }
            else
            {
                m_TouchDrawingView.Hide();
            }
        }
        #endregion
    }
}
